package com.huluobo.mvvmdemo1903a.mvc.controller;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.huluobo.mvvmdemo1903a.R;
import com.huluobo.mvvmdemo1903a.mvc.model.User;

/**
 * Created by lc on 2021/11/22.
 */
public class MvcLoginActivity extends AppCompatActivity {
    private EditText userNameEt, passwordEt;
    private User user;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mvc_login);

        user = new User();
        userNameEt = findViewById(R.id.user_name_et);
        passwordEt = findViewById(R.id.password_et);

        Button loginBtn = findViewById(R.id.login_btn);
        loginBtn.setOnClickListener(view -> login(userNameEt.getText().toString(),
                passwordEt.getText().toString()));
    }

    private void login(String userName, String password) {
        if (userName.equals("lc") && password.equals("123")) {
            user.setUserName(userName);
            user.setPassword(password);
            Toast.makeText(this, userName + "登录成功", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
        }
    }
}
